<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <% 
String path = request.getContextPath(); 
// 获得项目完全路径（假设你的项目叫MyApp，那么获得到的地址就是 http://localhost:8080/MyApp/）: 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 
<!DOCTYPE html>
<html>
<head>
<base href=" <%=basePath%>"> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="用户修改密码">
<meta name="author" content="xwj">
<title>重置密码</title>
<!-- <link rel="stylesheet" href="css/user_css/css/bootstrap.min.css" /> -->
<link href="bootstrap/bootstrap.css" rel="stylesheet">
        <link rel="stylesheet" href="css/user_css/css/font-awesome.min.css" />
        <!-- Custom CSS -->
        <link href="public_user/style.css" rel="stylesheet">
      <!-- 重置文件 -->
  <link rel="stylesheet" href="css/user_css/css/register/css/normalize.css">
  <link rel="stylesheet" href="css/user_css/css/register/css/style.css">  
  <!-- 表单验证 -->

  <script src="jquery/jquery-2.2.4.min.js"></script>
<script src="bootstrap/bootstrap.min.js"></script>
<script src="bootstrap/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
  <script>
	$(function() {
		 //表单验证
	    $("#pwd_form").bootstrapValidator({
	      message : 'This value is not valid',
	      feedbackIcons : {/*输入框不同状态，显示图片的样式*/
	        valid : 'glyphicon glyphicon-ok',
	        invalid : 'glyphicon glyphicon-remove',
	        validating : 'glyphicon glyphicon-refresh'
	      },
	      fields : {/*验证*/
	    	 oldpwd : {/*键名username和input name值对应*/
	          message : 'The cname is not valid',
	          validators : {
	            notEmpty : {/*非空提示*/
	              message : '用户名不能为空'
	            },
                remote:{ //查询是否有相同的用户名
                	url:"userMsg/getPwd.do",
                	type:"post",
                	data:{"oldpwd":$("input[name='oldpwd']").val()},
                	delay:2000, //2s后执行ajax
                	dataType:"json",
                	message:"密码错误"//提示信息
                }
	          }
	        },
	        newpwd : {
	          message : 'The cdesc is not valid',
	          validators : {
	            stringLength : {/*长度提示*/
	            	 min : 6,
	              max : 16,
	              message : '密码的长度必须在6到16之间'
	            },
	            regexp: {
                 	regexp: /^[a-zA-Z0-9_]{0,}$/,
                 	message: '密码必须是字母或数字' 
                 }
	          }
	        },
            repass: {
                message:'密码无效',
                validators: {
                    notEmpty: {
                        message: '不能为空'
                    },
                    identical: {
                    	field: 'newpwd',
                    	message: '两次密码必须一致'
                    }
                }
            }
	      }
	    });
	});
	
	//改变密码
	function changePwd() {
		var bv = $("#pwd_form").data('bootstrapValidator');
		bv.validate();
		if (!bv.isValid()) {
			return;
		}
		if (!confirm("确认要修改吗?")) {
			return;
		}
		var newpwd=$("input[name='newpwd']").val();
		$.ajax({
			url : 'userMsg/changePwd.do',
			type : 'POST',
			async : "true",
			data : {
				"newpwd":newpwd
			},
			dataType : 'json',
			success : function(data) {
				if (data.res == 1) {
					alert("修改成功，请重新登录~~");
					window.location.replace("public_user/login.jsp");
				}
			}
		});
		}
		</script>
  
  
</head>
<body >
<!--header start-->
     <%@include file="header.jsp"%>
      <!--header end-->
      <!-- heading-banner-start -->
        
        <!-- heading-banner-end -->
        
       <!-- main-start -->
       <div class="pwd_main">
       <div class="pwd_div">
  <div class="p_div"><p>修改密码</p></div>
<form class="form-horizontal" role="form" id="pwd_form">
           <div class="form-group">
              <label for="upwd" class="col-sm-3 control-label">原密码</label>
              <div class="col-sm-8">
                <input type="password" class="form-control" name="oldpwd" id="upwd"
                   placeholder="请输入原密码" />
              </div>
            </div>
     	<div class="form-group">
              <label for="firstname" class="col-sm-3 control-label">新密码</label>
              <div class="col-sm-8">
                <input type="password" class="form-control" name="newpwd" id=""
                   placeholder="请输入新密码" />
              </div>
            </div>
           <div class="form-group">
              <label for="firstname" class="col-sm-3 control-label">确认</label>
              <div class="col-sm-8">
                <input type="password" class="form-control"  id=""  name="repass"
                   placeholder="请输入确认密码" />
              </div>
            </div>
    
        <button class="my_btn" onClick="changePwd()">确认</button>
     
    </form>
  </div>
  </div>
        
         <!-- main-end -->
         <!--footer start-->
   <%@include file="footer.jsp"%>
   <!--footer end-->
     
        <!-- owl.carousel js -->
        <script src="css/user_css/js/owl.carousel.min.js"></script>
        <!-- meanmenu js -->
        <script src="css/user_css/js/jquery.meanmenu.js"></script>
        <!-- countdown js -->
        <script src="css/user_css/js/countdown.js"></script>
        <!-- jquery.nivo.slider.pack js -->
        <script src="css/user_css/js/jquery.nivo.slider.pack.js"></script>
        <!-- jquery-ui.min.js -->
        <script src="css/user_css/js/jquery-ui.min.js"></script>
        <!-- wow js -->
        <script src="css/user_css/js/wow.min.js"></script>
        <!-- plugins js -->
        <script src="css/user_css/js/plugins.js"></script>
        <!-- main js -->
        <script src="css/user_css/js/main.js"></script>

 <!--  <script type="text/javascript" src="css/user_css/css/register/js/script.js"></script> -->
        
</body>
</html>